package com.loancalculator.compoment;

import com.sun.lwuit.ComboBox;
import com.sun.lwuit.Component;
import com.sun.lwuit.Font;
import com.sun.lwuit.Label;
import com.sun.lwuit.List;
import com.sun.lwuit.list.ListCellRenderer;
import com.sun.lwuit.plaf.Border;

public class ComboBoxEx extends ComboBox {
	public ComboBoxEx() {
		super();
		initStyle(this);
	}

	public ComboBoxEx(Object[] arg0) {
		super(arg0);
		initStyle(this);
	}

	void initStyle(ComboBoxEx obj) {
		obj.setRenderer(new checkBoxRenderer());
		obj.getStyle().setBgColor(0x555ccc);
		obj.getStyle().setBorder(Border.createRoundBorder(12, 5));
		obj.getPressedStyle().setBgColor(0x555ccc);
		obj.getPressedStyle().setBorder(Border.createRoundBorder(12, 5));
		obj.getSelectedStyle().setBgColor(0x555ccc);
		obj.getSelectedStyle().setBorder(Border.createRoundBorder(12, 5));
	}

	private static class checkBoxRenderer extends Label implements
			ListCellRenderer {
		Font createFont() {
			Font font = Font.createSystemFont(Font.FACE_PROPORTIONAL,
					Font.STYLE_BOLD, Font.SIZE_SMALL);
			return font;
		}

		/** Creates a new instance of checkBoxRenderer */
		public checkBoxRenderer() {
			super("");
		}

		// Setting the current check box text and status
		public Component getListCellRendererComponent(List list, Object value,
				int index, boolean isSelected) {
			setText("" + value);
			getStyle().setFont(createFont());
			getStyle().setBgTransparency(0);

			if (isSelected) {
				setFocus(true);
				// setSelected(true);
			} else {
				setFocus(false);
				// setSelected(false);
			}
			return this;
		}

		// Returning the list focus component
		public Component getListFocusComponent(List list) {
			setText("");
			setFocus(true);
			// setSelected(true);
			return this;
		}
	}
}
